package cn.kimming.wms.query;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import lombok.Getter;
import lombok.Setter;

public class QueryObject {
	
	@Getter @Setter
	private int currentPage = 1;	//当前页
	@Getter @Setter
	private int pageSize = 10;	//每页显示记录数
	@Getter @Setter
	private int total = 0;	//总记录数
	
	private List<String> conditions = new ArrayList<>();
	@Getter
	private List<Object> params = new ArrayList<>();
	private boolean build;
	
	protected void customizedQuery() {
		
	}
	
	public String getQuery() {
		init();
		if (conditions.size() == 0) {
			return "";
		}
		return " WHERE " + StringUtils.join(conditions, " AND ");
	}
	
	private void init() {
		if (!build) {
			customizedQuery();
		}
	}
	
	protected void addCondition(String condition, Object... args) {
		conditions.add(condition);
		params.addAll(Arrays.asList(args));
	}
	
}
